package org.lanqiao.api.admin;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.common.Constants;
import org.lanqiao.common.JsonResult;
import org.lanqiao.common.JsonResultWriter;
import org.lanqiao.pojo.PageModel;
import org.lanqiao.pojo.ProductPOJO;
import org.lanqiao.service.AdminServiceImpl;

/**
 * 添加商品
 * Servlet implementation class AddProductsServlet
 */
@WebServlet("/api/admin/AddProductsServlet")
public class AddProductsServlet extends HttpServlet {
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
	
			String color=request.getParameter("Color");
			String standard=request.getParameter("Standard");
			String categoryId=request.getParameter("categoryId");
			String brandId=request.getParameter("brandId");
			String photo=request.getParameter("Photo");
			String Comment=request.getParameter("Comment");
			String name=request.getParameter("Productname");		
			String code=request.getParameter("Productcode");
			String price=request.getParameter("Price");		
			String suggestPrice=request.getParameter("suggestPrice");
			String unit=request.getParameter("Unit");
			ProductPOJO pro=new ProductPOJO();
			pro.setProductComment(Comment);
			pro.setBrandId(brandId);
			pro.setPhoto(photo);
			pro.setProductColor(color);
			pro.setCategoryId(categoryId);
			pro.setStandard(standard);
			pro.setProductName(name);
			pro.setProductCode(code);
			pro.setPrice(price);
			pro.setSuggestPrice(suggestPrice);
			pro.setUnit(unit);
			/**
			 * 调用修改用户方法
			 */
			AdminServiceImpl abc=new AdminServiceImpl();
			JsonResult result=null;
			try {
				int model=abc.addProduct(pro);
				if(model>0){
					result=new JsonResult("添加成功",Constants.STATUS_SUCCESS,model);
				}else {
					result=new JsonResult("添加错误",Constants.STATUS_UNFOUND);
				}
			} catch (Exception e) {
				result=new JsonResult("添加异常",Constants.STATUS_FAILURE);
			}
			JsonResultWriter.writer(response, result);;
	}

}
